﻿using System;
using System.Collections.Generic;
using System.Data;
using Microsoft.Reporting.WebForms;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace IMIS_ERP.Web.Order_Info
{
    public partial class Report_Manage_Agent_Credit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["UType1"].ToString() != "0" && Session["UType1"].ToString() != "1")
                {
                    Response.Write("<script>alert('没有权限！');location.href='../ERP_Manager/EM_Page_Main.aspx';</script>");
                }
                Data_Bind("2110-1-1");
            }
        }

        private void Data_Bind(string strTime)
        {
            IMIS_ERP.BLL.Order_Products bll = new BLL.Order_Products();
            DataSet ds = bll.GetShopCredit_Agent(strTime);
            DataTable dt = ds.Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (!dt.Rows[i]["aiArea"].ToString().Contains(dt.Rows[i]["siCity"].ToString()))
                {
                    dt.Rows[i].Delete();
                }
            }
            dt.AcceptChanges();
            if (Session["UType1"].ToString() == "1")
            {
                DataView dv = dt.DefaultView;
                dv.RowFilter = "aiProvince='" + Session["UProvince"].ToString() + "'";
                dt = dv.ToTable();
            }
            ReportDataSource rds = new ReportDataSource("ds", dt);
            this.RV.LocalReport.DataSources.Clear();
            this.RV.LocalReport.DataSources.Add(rds);
            this.RV.DataBind();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string time = "2110-1-1";
            if (txthTime.Text != "")
            {
                time = txthTime.Text.Trim() + " 23:59:59";
            }
            Data_Bind(time);
        }
    }
}